package com.hzdl.house_mgr.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzdl.house_mgr.bean.House;
import com.hzdl.house_mgr.bean.Img;
import com.hzdl.house_mgr.mapper.HouseMapper;
import com.hzdl.house_mgr.service.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HouseServiceImpl implements HouseService {

    @Autowired
    private HouseMapper houseMapper;


    @Override
    public PageInfo<House> findAllByWhere(House house,Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<House> all = houseMapper.findAllByWhere(house);
        return new PageInfo<House>(all);
    }

    @Override
    public int getCountByWhere(House house) {
        return houseMapper.getCountByWhere(house);
    }

    @Override
    public int addHouse(House house) {
        return houseMapper.addHouse(house);
    }

    @Override
    public int updateHouse(House house) {
        return houseMapper.updateHouse(house);
    }

    @Override
    public int deleteHouse(Integer houseId) {
        return houseMapper.deleteHouse(houseId);
    }

    @Override
    public int deleteAllHouse(String[] houseIds) {
        int x=0;
        if (houseIds != null && houseIds.length !=0)
            for (String i: houseIds){
                int y= Integer.parseInt(i);
                return x+=deleteHouse(y);
            }
        return x;
    }

    @Override
    public House findHouse(Integer houseId) {
        return houseMapper.findHouse(houseId);
    }

    @Override
    public House findHouseByHid(Integer houseId) {
        return houseMapper.findHouseByHid(houseId);
    }

    @Override
    public List<Img> findImgById(Integer houseId) {
        return houseMapper.findImgById(houseId);
    }

    @Override
    public  List<House> findByWhere(String community) {
        return houseMapper.findByWhere(community);
    }

    @Override
    public int getCountByWhere1(String community) {
        return houseMapper.getCountByWhere1(community);
    }

    @Override
    public List<House> findAll() {
        return houseMapper.findAll();
    }





    @Override
    public int getCount() {
        return houseMapper.getCount();
    }

    @Override
    public House findById(int houseId) {
        return houseMapper.findById(houseId);
    }

    @Override
    public int pushHouse(House house) {
        return houseMapper.pushHouse(house);
    }
}
